﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using DslModeling=global::Microsoft.VisualStudio.Modeling;
using DslDesign=global::Microsoft.VisualStudio.Modeling.Design;
using DslDiagrams=global::Microsoft.VisualStudio.Modeling.Diagrams;
using DslValidation=global::Microsoft.VisualStudio.Modeling.Validation;

namespace Salamanca.Saml
{

    [DslValidation.ValidationState(DslValidation.ValidationState.Enabled)]
    partial class DataAttribute:
        INamedElement
    {
        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification="Domain property calculated value")]
        public string GetNameAndTypeValue()
        {
            return this.Name.Trim()+" : "+this.Type.Trim();
        }

        /// <summary>Ensures that names will be valid C# identifiers.</summary>
        [DslValidation.ValidationMethod(DslValidation.ValidationCategories.Menu | DslValidation.ValidationCategories.Open | DslValidation.ValidationCategories.Save)]
        private void ValidateName(DslValidation.ValidationContext context)
        {
            NamedElement.ValidateName(context, this);
        }

        [DslValidation.ValidationMethod(DslValidation.ValidationCategories.Menu|DslValidation.ValidationCategories.Open|DslValidation.ValidationCategories.Save)]
        private void ValidateType(DslValidation.ValidationContext context)
        {
            if (string.IsNullOrEmpty(Type))
            {
                context.LogError(
                    Resources.SR.DataAttributeMustHaveType,
                    "SAML01",
                    this
                );
                return;
            }
        }
    }
}
